<?php

/**
 * 订单产品模型
 * 模型对应数据库表 "orders_items".
 *
 * 以下是可用表orders_items的栏位:
 * @property integer $id
 * @property string $order_number
 * @property integer $pid
 * @property string $product_type
 * @property string $name
 * @property string $info
 * @property string $price
 * @property integer $num
 * @property string $game
 * @property string $game_server
 * @property string $input
 * @property string $gold_num
 */
class OrdersItems extends CActiveRecord {

    /**
     * 返回指定的基于“ar”的静态模型类.
     * @return OrdersItems the static model class
     * @author nirsh
     * @example
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * 返回数据库表的名.
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function tableName() {
        return 'orders_items';
    }

    /**
     * 返回验证规则
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function rules() {
        return array(
            array('pid, num', 'numerical', 'integerOnly' => true),
            array('order_number', 'length', 'max' => 20),
            array('product_type, name, game, game_server', 'length', 'max' => 255),
            array('price, gold_num', 'length', 'max' => 10),
            array('info, input', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, order_number, pid, product_type, name, info, price, num, game, game_server, input, gold_num', 'safe', 'on' => 'search'),
        );
    }

    /**
     * 返回关联规则数组。
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * 通过ID获取名称
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function getNameById($id, $nameField) {
        $res = $this->findByPk($id);
        return $res[$nameField] ? $res[$nameField] : '';
    }

    /**
     * 返回属性标签(名称= >标签)数组
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'order_number' => '订单编号',
            'pid' => '产品ID',
            'product_type' => '产品类型',
            'name' => '产品名称',
            'info' => '产品描述',
            'price' => '单价',
            'num' => '数量',
            'game' => '游戏',
            'game_server' => '服务区',
            'input' => '客户游戏信息',
            'gold_num' => '金币数量',
        );
    }

    /**
     * 设置查询相关条件
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('order_number', $this->order_number, true);
        $criteria->compare('pid', $this->pid);
        $criteria->compare('product_type', $this->product_type, true);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('info', $this->info, true);
        $criteria->compare('price', $this->price, true);
        $criteria->compare('num', $this->num);
        $criteria->compare('game', $this->game, true);
        $criteria->compare('game_server', $this->game_server, true);
        $criteria->compare('input', $this->input, true);
        $criteria->compare('gold_num', $this->gold_num, true);

        return new CActiveDataProvider(get_class($this), array(
                    'criteria' => $criteria,
                ));
    }

}